<?php
/*
 * SDOSelfCheck
 * SDO自检类型
 * 读取自检配置后逐个运行自检项目
 * @author： Wolfhead <meixueting@snda.com>
 */



class SDOSelfCheck
{
    static function run($Item)
    {
        $config = require dirname(__FILE__) . "/../config/SDOSelfCheckConfig.php";
        
        $items = explode("|" ,$Item);
        
        $data = array();
        
        foreach ($items as $item)
        {
            $item = $config[$item];
            
            if (empty($item))
            {
                break;
            }
            
            require $item['file'];
            
            $p = new ReflectionClass($item['class']);
            
            $methods = $p->getMethods();
            
            
            foreach ($methods as $method)
            {
                if (strpos($method->name, "case") === 0)
                {
                    $result = array();
                    $result = call_user_func($method->class . "::" . $method->name);
                    
                    $name = 'OA.' . $method->class . "." . $method->name;
                    $result['timestamp'] = time();
                    
                    $data[$name] = $result;
                }
            }
        }
        
        return json_encode($data);
    }
   
}


$item    = $_GET["item"];
$sig    = $_GET["sig"];
$time    = $_GET["time"];


if ($sig !== md5("147896325"))
{
    die();
}

if (time() - $time > 3600 * 1)
{
    die();
}

echo SDOSelfCheck::run($item);


die();

